package util;

public class Partition implements IPartition {
	String[] hosts = null;

	public Partition(String[] hosts_) {
		this.hosts = hosts_;
	}

	public int shard(String key) {
		if (hosts.length == 1)
			return 0;
		CRC16 crc = new CRC16();
		int crcRes = (int) crc.caluCRC(key.getBytes()) % 4096;
		float tmp = ((float) 4096) / hosts.length;
		return (int) (crcRes / tmp);
	}

	public int shardFol(String key) {
		if (hosts.length == 1)
			return 0;
		CRC16 crc = new CRC16();
		int crcRes = (int) crc.caluCRC(key.getBytes()) % 4096;
		float tmp = ((float) 4096) / hosts.length;
		return (int) (crcRes / tmp);
	}

	public int shardStatus(String key) {
		if (hosts.length == 1)
			return 0;
		CRC16 crc = new CRC16();
		int crcRes = (int) crc.caluCRC(key.getBytes()) % 4096;
		float tmp = ((float) 4096) / hosts.length;
		return (int) (crcRes / tmp);
	}

	public int shardMetaData(String key) {
		return 0;
	}
}
